﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lm.Common.Auth.Client
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void 登录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Root.ClientRoot.LoginForm.ShowDialog();
        }

        public void SetLoginStatus(string loginStatus)
        {
            this.lblLoginStatus.Text = loginStatus;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Root.ClientRoot.LoginInfo.ClearLoginInfo();
            Root.ClientRoot.LoginForm.ShowDialog();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Root.ClientRoot.ChangePasswordForm.ShowDialog();
        }

        private void 角色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.ShowDockForm<Role.RoleListForm>();
        }

        public void ShowDockForm<T>() where T : WeifenLuo.WinFormsUI.Docking.DockContent, new()
        {
            var dockFormList = this.dockPanel1.Contents.ToDictionary(t => t.GetType());
            if (dockFormList.ContainsKey(typeof(T)))
            {
                var form = dockFormList[typeof(T)];
                form.DockHandler.Activate();
            }
            else
            {
                new T().Show(this.dockPanel1);
            }
        }

        private void 账号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.ShowDockForm<Account.AccountListForm>();
        }

        private void 我的授权ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.ShowDockForm<TempAuthorize.TempAuthorizeForm>();
        }
    }
}
